import asyncio

from service.server.server_manager import ServerManager

async def main():
    server_manager = ServerManager()
    for i in range(10):
        server_manager.add_modbus_tcp_server(f"tcp_server_{i}", ip="127.0.0.1", port=502 + i)
        server = server_manager.get_server(f"tcp_server_{i}")
        server.add_slave_co(1, start_address=0, end_address=65535)
        server.add_slave_hr(1, start_address=0, end_address=65535)
        server.add_slave_ir(1, start_address=0, end_address=65535)
        server.add_slave_di(1, start_address=0, end_address=65535)
    server_manager.start_all_servers()
    # 保持事件循环运行
    while True:
        await asyncio.sleep(1)
        server_manager.get_server("tcp_server_0").get_latest_message()


if __name__ == "__main__":
    asyncio.run(main())
